import { useState, useEffect } from "react";

function App() {
    const [count, setCount] = useState(0);

    useEffect(() => {   // 挂载完成后
        // const timer = setInterval(() => {
        //     setCount(count + 1)
        // })

        return () => {
            console.log('卸载了');
            clearInterval(timer);  
        }
    }, [count])

    const add = () => {
        setCount(count + 1);
    }

    return (
        <button onClick={add}>{count}</button>
    )
}

export default App;